package com.qfjy.project.meeting;
import com.qfjy.entity.MeetingPub;
import com.qfjy.entity.User;
import com.qfjy.service.MeetingPubService;
import com.qfjy.uitl.ResultCode;
import com.qfjy.uitl.ResultJson;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
@Controller
@RequestMapping ("meetingpub")
@Slf4j
@Api(tags = {"会议的发单"})
public class MeetingPubController {
    @Autowired
    private MeetingPubService meetingPubService;
    @ResponseBody
   @PostMapping("meetingPubAdd")
    public ResultJson meetingPubAdd(MeetingPub meetingPub){
        System.out.println(meetingPub);
        int num=0;
           num = meetingPubService.insert(meetingPub);
       if(num==1){
           log.info("会议发布成功");
          return new ResultJson(num, ResultCode.SUCCESS);
       }
        return new ResultJson(null,ResultCode.FAIL);
    }
    @RequestMapping("meetpubAddtoPage")
    public String meetpubAddtoPage(HttpServletRequest request){
        request.setAttribute("uid",1);
        return "pages/meetingpub/meetingpubAdd";
    }
    /**
     * 我发布的会议
     */
@RequestMapping("selectListMeetingPubByUid")
@ResponseBody
    public ResultJson selectListMeetingPubByUid(@RequestParam("uid") String uid){
    System.out.println(uid);
    //System.out.println("进入机内");
    List<MeetingPub> meetingPubs = meetingPubService.selectMeetingPubList(uid);
    if(meetingPubs.size()==0){
        log.info("用户发布会议为空");
          return new ResultJson(null,ResultCode.NOT_DATA);
    }
    return new ResultJson(meetingPubs,ResultCode.SUCCESS);
    }

    /**
     * 跳转讲者列表
     */
    @RequestMapping("chooseGrabList")
    public String chooseGrabList(HttpServletRequest request){
        String pid = request.getParameter("pid");
         request.setAttribute("pid",pid);
         return "pages/meetingpub/grabList";
    }
   @ResponseBody
   @GetMapping("selectListUserByPid")
   public List<User> selectListUserByPid(String pid){
       System.out.println(pid);
       List<User> users = meetingPubService.selectUserByPid(pid);
       System.out.println(users);
       return users;
   }
    /**
     * 就选你功能
     */
    @ResponseBody
   @GetMapping("chooseUserMeeting")
    public ResultJson chooseUserMeeting(@RequestParam("uid") String uid, @RequestParam("pid") String pid) {
        System.out.println("pidpidpidpidpidpidpidpidpidpidpidpidpidpidpidpidpidpidpidpid"+pid);
        int i=0;
        try{
             i = meetingPubService.chooseUserMeeting(uid, pid);
             return  new ResultJson(i,ResultCode.SUCCESS);
        }catch (Exception e){
            log.error(e.getMessage());
        }


        return new ResultJson(0,ResultCode.FAIL);
    }
}